package forum_system_test;

import org.junit.jupiter.api.*;
import org.junit.platform.suite.api.SelectPackages;
import org.junit.platform.suite.api.Suite;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/**
 * @author tongchen
 * @create 2023-08-19 20:41
 */
@Suite
@SelectPackages("src")
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class PostCenterTest {
    private static ChromeDriver chromeDriver =TestUtils.getDriver();
    @BeforeAll
    public static void loginAndClick() throws InterruptedException {
        chromeDriver.get("http://47.93.222.41:58080/sign-in.html");
        WebElement element = chromeDriver.findElement(By.cssSelector("#username"));
        WebElement element1 = chromeDriver.findElement(By.cssSelector("#password"));
        WebElement element2 = chromeDriver.findElement(By.cssSelector("#submit"));
        element.clear();
        element1.clear();
        element.sendKeys("刘健磊");
        element1.sendKeys("123456");
        //强制等待一秒，使新页面能加载出来
        element2.click();
        Thread.sleep(5000);
        //寻找具体元素并打开
        chromeDriver.findElement(By.cssSelector("#index_nav_avatar ")).click();
        chromeDriver.findElement(By.cssSelector("#index_user_profile")).click();
    }
    @Order(2)
    @Test
    public void testElement() throws InterruptedException {
        //等待资源全部加载完成
        Thread.sleep(3000);
        chromeDriver.findElement(By.cssSelector("#profile_avatar"));
        chromeDriver.findElement(By.cssSelector("#profile_nickname"));
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1)"));
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(2)"));
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(3)"));
        chromeDriver.findElement(By.cssSelector("#profile_article_body > li > div.card.timeline-event-card > div > div > div > div > div.text-truncate"));
        chromeDriver.findElement(By.cssSelector("#profile_article_body > li > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col > ul > li"));
        chromeDriver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div.col-lg-4 > div > div > div > div"));
        chromeDriver.findElement(By.cssSelector("#profile_article_body > li > div.card.timeline-event-card > div > div > div > div > div.text-muted.mt-2 > div > div.col-auto.d-none.d-md-inline > ul"));
    }
}
